
/* Generated by Interface Builder */

#import "WaterfallComputer.h"
#import "Spectro.h"
#import "SignalProcessor.h"
#import <soundkit/soundkit.h>
#import <math.h>

@implementation WaterfallComputer

extern int data_size,power_of_four,window_size,num_frames,total_data,s_rate,mono_file;
extern float f[16384],freq_max;
extern BOOL running_analysis,one_time,waterfall;
extern char window_type[200];
extern int firstSample,sampleCount;
extern float ceiling,flor;

id mySignalProcessor,myApp;

- setApp:anObject
{
    myApp = anObject;
    return self;
}

- setSignalProcessor:anObject
{
    mySignalProcessor = anObject;
    return self;
}

- computeThisCodex: (unsigned char *) data
{
	int i,j,k,stopping = 0;
	for (j=num_frames-1;j>=0 && one_time && !stopping;j--)	{
	    k = j * window_size * 0.5;
	        for (i=0;i<window_size;i++) f[i] = (float) SNDiMulaw(data[i +k + firstSample]);
	    for (i=window_size;i<data_size;i++) f[i] = 0.0;
	    [mySignalProcessor window: window_size array: f type: window_type phase: FALSE];
	    [mySignalProcessor fhtRX4: power_of_four array: f];
	    [mySignalProcessor logMag: data_size array: f floor: flor ceiling: ceiling];
	    stopping = [myApp passThisToWFViewPlease:  f ];
	}
	return self;
}

- computeThisLinear: (short *) data
{
	int i,j,k,stopping = 0;
	for (j=num_frames-1;j>=0 && one_time && !stopping;j--)	{
	    k = j * window_size * 0.5;
	    if (mono_file==2)
		    for (i=0;i<window_size;i++) f[i] = (float) data[i+ k + firstSample];
	    if (mono_file==1)
		    for (i=0;i<window_size;i++) f[i] = (float) (data[2*(i+ k + firstSample)] + 
		    				data[2*(i + k + firstSample) + 1]) * 0.5;
	    if (mono_file==0)
		    for (i=0;i<window_size;i++) f[i] = (float) data[2*(i + k + firstSample) + 1];
	    if (mono_file==-1)
		    for (i=0;i<window_size;i++) f[i] = (float) data[2*(i + k + firstSample) ];
	    for (i=window_size;i<data_size;i++) f[i] = 0.0;
	    [mySignalProcessor window: window_size array: f type: window_type phase: FALSE];
	    [mySignalProcessor fhtRX4: power_of_four array: f];
	    [mySignalProcessor logMag: data_size array: f floor: flor ceiling: ceiling];
	    stopping = [myApp passThisToWFViewPlease:  f ];
	}
	return self;
}
@end
